/*
 * #%L
 * SwiftUICommonUtilities
 * $Id:$
 * $HeadURL:$
 * %%
 * Copyright (C) 2011 - 2012 Linkwithweb
 * %%
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as
 * published by the Free Software Foundation, either version 3 of the 
 * License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public 
 * License along with this program.  If not, see
 * <http://www.gnu.org/licenses/gpl-3.0.html>.
 * #L%
 */
/**
 * 
 */
package com.linkwithweb.products.swiftui.spring.jdbc;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import com.linkwithweb.products.swiftui.dataobject.BaseDataObject;

/**
 * This Object Represents Any Data Object That is Loaded from database. Note:
 * This represents Logical Table Name Registered in database if loaded from
 * dynamic sql
 * 
 * @author ashwin
 * 
 */
public class DBEntityComponent extends BaseDataObject {

	private Long id = 0L;
	private String entityName = "";
	private String entityDescription = "";
	private String entityType = "";

	public static interface EntityTypes {
		public static String TABLE = "TABLE";
		public static String SQL = "SQL";
	}

	private String entityValue = "";
	private String schemaName = "";

	// We are not supporting composite Keys for now
	private String primaryKey = "";

	// To Store Column Types Derived From Database Queries
	private Map<Integer, ColumnMetadata> columnTypeMetadata = new LinkedHashMap<Integer, ColumnMetadata>();
	

	/**
	 * @return the id
	 */
	public Long getId() {
		return id;
	}

	/**
	 * @param id
	 *            the id to set
	 */
	public void setId(Long id) {
		this.id = id;
	}

	/**
	 * @return the entityName
	 */
	public String getEntityName() {
		return entityName;
	}

	/**
	 * @param entityName
	 *            the entityName to set
	 */
	public void setEntityName(String entityName) {
		this.entityName = entityName;
	}

	/**
	 * @return the entityDescription
	 */
	public String getEntityDescription() {
		return entityDescription;
	}

	/**
	 * @param entityDescription
	 *            the entityDescription to set
	 */
	public void setEntityDescription(String entityDescription) {
		this.entityDescription = entityDescription;
	}

	/**
	 * @return the columnTypeMetadata
	 */
	public Map<Integer, ColumnMetadata> getColumnTypeMetadata() {
		return columnTypeMetadata;
	}

	/**
	 * @param columnTypeMetadata
	 *            the columnTypeMetadata to set
	 */
	public void setColumnTypeMetadata(
			Map<Integer, ColumnMetadata> columnTypeMetadata) {
		this.columnTypeMetadata = columnTypeMetadata;
	}

	/**
	 * @param columnName
	 * @param metadata
	 */
	public void addColumnMetadata(Integer columnName, ColumnMetadata metadata) {
		this.columnTypeMetadata.put(columnName, metadata);
	}

	/**
	 * @return the primaryKey
	 */
	public String getPrimaryKey() {
		return primaryKey;
	}

	/**
	 * @param primaryKey
	 *            the primaryKey to set
	 */
	public void setPrimaryKey(String primaryKey) {
		this.primaryKey = primaryKey;
	}

	/**
	 * @return the entityType
	 */
	public String getEntityType() {
		return entityType;
	}

	/**
	 * @param entityType
	 *            the entityType to set
	 */
	public void setEntityType(String entityType) {
		this.entityType = entityType;
	}

	/**
	 * @return the entityValue
	 */
	public String getEntityValue() {
		return entityValue;
	}

	/**
	 * @param entityValue
	 *            the entityValue to set
	 */
	public void setEntityValue(String entityValue) {
		this.entityValue = entityValue;
	}

	/**
	 * @return the schemaName
	 */
	public String getSchemaName() {
		return schemaName;
	}

	/**
	 * @param schemaName
	 *            the schemaName to set
	 */
	public void setSchemaName(String schemaName) {
		this.schemaName = schemaName;
	}

	public List<ColumnMetadata> getColumnsList() {
		List<ColumnMetadata> columnsMetadata = new ArrayList();
		for (Iterator iterator = columnTypeMetadata.entrySet().iterator(); iterator
				.hasNext();) {
			Map.Entry entry = (Map.Entry) iterator.next();
			ColumnMetadata value = (ColumnMetadata) entry.getValue();
			columnsMetadata.add(value);
		}

		return columnsMetadata;
	}

}
